package controller

import (
	"github.com/gin-gonic/gin"
	"yak.admin/src/entity"
	"yak.admin/src/middleware"
	"yak.admin/src/module/backend/hnyj/repository"
	"yak.admin/src/service"
	"yak.admin/src/util"
)

type HomeController struct {

}

func Home(c *gin.Context) {
	admin := c.MustGet(util.AdminKey).(entity.Admin)
	var page middleware.Page
	behavior := service.BehaviorService{}
	if admin.Type == util.TypeDrug {
		repos := repository.DrugReportRepository{}
		page = middleware.Page{
			Title:  "风险一览",
			Linker: "/",
			Tpl:    "hnyj/home/drug.tpl",
			Data: map[string]interface{}{
				"report": behavior.Drug(admin.Province, admin.City, admin.County),
				"daily": behavior.DrugDaily(admin.Province, admin.City, admin.County),
				"newly": repos.PendingReports(c, admin),
			},
		}
	}
	if admin.Type == util.TypeDevice {
		repos := repository.DeviceReportRepository{}
		page = middleware.Page{
			Title:  "风险一览",
			Linker: "/",
			Tpl:    "hnyj/home/device.tpl",
			Data: map[string]interface{}{
				"report": behavior.Device(admin.Province, admin.City, admin.County),
				"daily": behavior.DeviceDaily(admin.Province, admin.City, admin.County),
				"newly": repos.PendingReports(c, admin),
			},
		}
	}
	c.Set("Page", page)

}
